//个别组件
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import moment from 'moment'
// import Vant from 'vant'
import 'vant/lib/index.css'
//vant组件
import { Field, Toast, List, Cell, CellGroup, Dialog, RadioGroup, Button, Radio, Uploader } from 'vant'
import { Tab, Tabs } from 'vant';
import { PullRefresh } from 'vant';

Vue.use(PullRefresh);
Vue.use(Tab);
Vue.use(Tabs);
Vue.use(Field)
Vue.use(Toast)
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Dialog);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(Uploader);
Vue.use(Button);
Vue.use(List);

import './styles/base.less'
import './styles/iconfont.css'
import 'lib-flexible'
//axios内部设置
import axios from 'axios'
axios.defaults.baseURL = 'http://localhost:3000'
Vue.prototype.$axios = axios
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  const token = localStorage.getItem('token')
  config.headers.Authorization = token
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});
axios.interceptors.response.use(res => {
  const { statusCode, message } = res.data
  if (statusCode == 401 && message === '用户信息验证失败') {
    localStorage.removeItem('token')
    localStorage.removeItem('id')
    router.push('/login')
  }
  return res
})
Vue.config.productionTip = false
//组件引入
import ShopHeader from './components/Shop-Header.vue'
import Logo from './components/Logo.vue'
import ShopButton from './components/ShopButton.vue'
import MyLove from './components/MyLove.vue'
import LoverHeader from './components/LoveHeader.vue'
Vue.filter('date', (date, format = 'YYYY-MM-DD') => {
  return moment(date).format(format)
})
Vue.component('mylove', MyLove)
Vue.component('shop-header', ShopHeader)
Vue.component('logo', Logo)
Vue.component('shop-button', ShopButton)
Vue.component('lover-header', LoverHeader)
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
